﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading;
using BrainTechLLC.ThreadSafeObjects;

namespace BrainTechLLC
{
	public class WorkItemQueueHandler
	{
		public int _handlesQueueNumber;
		public ThreadStart _threadStart;
		public Thread _workerThread;

		private SchedulingEngine _schedulingEngine;

		public WorkItemQueueHandler() { }

		public WorkItemQueueHandler(SchedulingEngine engine, int handlesQueueNumber)
		{
			_schedulingEngine = engine; _handlesQueueNumber = handlesQueueNumber;
		}

		private ThreadSafeQueue<IExecutableWorkItem> AssociatedWorkItemQueue
		{
			get { return _schedulingEngine._allWorkItemQueues[_handlesQueueNumber]; }
		}

		public void HandleAndExecuteWorkItems()
		{
			_schedulingEngine.HandleWorkItemQueue(_handlesQueueNumber);
		}

		public void StartEventHandler()
		{
			_threadStart = new ThreadStart(HandleAndExecuteWorkItems);
			_workerThread = _threadStart.CreateAndRunThread();
		}
	}
}